
package net.beaconcontroller.comp416project.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.openflow.protocol.OFFlowMod;

import net.beaconcontroller.comp416project.model.Model;
import net.beaconcontroller.comp416project.view.FlowChangeView;
import net.beaconcontroller.comp416project.view.View;
/**
 * 
 * @author SHI ZHONGQI 10836265D from HK PolyU
 * @author JI ZHIHAO 13022865X from HK PolyU
 *
 */
public class Controller implements  ActionListener{
	  private Model model;
	  private View view;
	  
	  public Controller(View view, Model model) {
		     this.view = view;
		     this.model = model;
	
	  }
	  
	  public void actionPerformed(ActionEvent e) {  
		  String command = e.getActionCommand();
		  
		  if(command.equals("FCV_Confirm")){
			  FlowChangeView fcv = view.getFCV();
			 //System.out.println("Hello");
			  if(fcv.getNewFlow())
				model.addFlow(fcv.getTheFlowMod());
			  else
				model.modifyFlow(fcv.getName(), fcv.getTheFlowMod());
			  
			  fcv.dispose();
			  return;
		  }
		  if(command.equals("FCV_Delete")){
			  FlowChangeView fcv = view.getFCV();
			  if(model.deleteFlow(fcv.getName()))
				  fcv.dispose();
				  else{
					  System.out.println("What Happens? "+fcv.getName());
				  }
			  return;
		  }
		  if(command.equals("FCV_Cancel")){
			  FlowChangeView fcv = view.getFCV();
			  fcv.dispose();
			  return;
		  }
		  if(command.equals("View_addFlow")){
			  view.openFCV();
			  return;
		  }
			  if(Model.getFlowMap().containsKey(command)){
				  view.openFCV(Model.getFlowMap().get(command),command);
			  }
	  }
	  
	
	  

}
